<!--
 * @Author: xiaodong 565071984@qq.com
 * @Date: 2022-05-09 21:35:06
 * @LastEditors: xiaodong 565071984@qq.com
 * @LastEditTime: 2022-05-11 22:41:41
 * @FilePath: /ywl/Volumes/ExtremeSSD/项目/小票/src/views/systemManagement/roleManagement/components/UserManagementEdit.vue
 * @Description: 这是默认设置,请设置`customMade`, 打开koroFileHeader查看配置 进行设置: https://github.com/OBKoro1/koro1FileHeader/wiki/%E9%85%8D%E7%BD%AE
-->
<template>
  <el-dialog
    :title="title"
    :visible.sync="dialogFormVisible"
    width="900px"
    @close="close"
  >
    <el-row :gutter="20">
      <el-col :xs="24" :sm="24" :md="24" :lg="12" :xl="12">
        <el-form
          ref="form"
          :model="ruleForm"
          :rules="rules"
          label-width="100px"
          class="demo-ruleForm"
        >
          <el-form-item
            :label="$t('accountManage.specialCodeAdds') /*特码赔率*/"
            prop="tema_rate"
          >
            <el-input v-model="ruleForm.tema_rate"></el-input>
          </el-form-item>
          <el-form-item
            :label="$t('accountManage.specialCodeOnLine') /*特码上限*/"
            prop="tema_up"
          >
            <el-input v-model="ruleForm.tema_up"></el-input>
          </el-form-item>
          <el-form-item
            :label="$t('accountManage.specialCodeOffLine') /*特码下限*/"
            prop="tema_down"
          >
            <el-input v-model="ruleForm.tema_down"></el-input>
          </el-form-item>
          <el-form-item
            :label="$t('accountManage.specialCodeExtraction') /*特码抽成*/"
            prop="tema_get_rate"
          >
            <el-input v-model="ruleForm.tema_get_rate"></el-input>
          </el-form-item>
          <el-form-item
            :label="$t('accountManage.orderReissued') /*订单重打*/"
            prop="order_retry"
          >
            <el-radio-group v-model="ruleForm.order_retry">
              <el-radio :label="0">
                {{ $t('accountManage.none') /*无*/ }}
              </el-radio>
              <el-radio :label="1">
                {{ $t('accountManage.has') /*有*/ }}
              </el-radio>
            </el-radio-group>
          </el-form-item>
          <el-form-item
            :label="$t('accountManage.redemption') /*兑奖日期*/"
            prop="cash_day"
          >
            <el-input v-model="ruleForm.cash_day"></el-input>
          </el-form-item>
          <el-form-item
            :label="$t('accountManage.receiptInfomation') /*小票打印信息*/"
            prop="print_info"
          >
            <el-input v-model="ruleForm.print_info" type="textarea"></el-input>
          </el-form-item>
          <el-form-item
            :label="$t('accountManage.orderNumber') /*禁购号码*/"
            prop="is_forbiden"
          >
            <el-radio-group v-model="ruleForm.is_forbiden">
              <el-radio :label="0">
                {{ $t('accountManage.shut') /*关闭*/ }}
              </el-radio>
              <el-radio :label="1">
                {{ $t('accountManage.shut') /*关闭*/ }}
              </el-radio>
            </el-radio-group>
            <!-- <el-button type="primary" plain>添加</el-button> -->
          </el-form-item>

          <el-form-item label="" prop="fbcode_list">
            <el-tag
              v-for="tag in ruleForm['fbcode_list']"
              :key="tag"
              closable
              :disable-transitions="false"
              @close="handleClose(tag)"
            >
              {{ tag['code'] }}
            </el-tag>
            <el-input
              v-if="inputVisible"
              ref="saveTagInput"
              v-model="inputValue"
              class="input-new-tag"
              size="small"
              @keyup.enter.native="handleInputConfirm"
              @blur="handleInputConfirm"
            ></el-input>
            <el-button
              v-else
              class="button-new-tag"
              size="small"
              @click="showInput"
            >
              + New Tag
            </el-button>
          </el-form-item>
        </el-form>
      </el-col>
      <el-col :xs="24" :sm="24" :md="24" :lg="12" :xl="12">
        <el-form
          ref="ruleForm"
          :model="ruleForm"
          :rules="rules"
          label-width="120px"
          class="demo-ruleForm"
        >
          <el-form-item
            :label="$t('accountManage.isAdditionSubtraction') /*是否有加奖*/"
            prop="is_add"
          >
            <el-radio-group v-model="ruleForm.is_add">
              <el-radio :label="0">
                {{ $t('accountManage.none') /*无*/ }}
              </el-radio>
              <el-radio :label="1">
                {{ $t('accountManage.has') /*有*/ }}
              </el-radio>
            </el-radio-group>
          </el-form-item>
          <el-form-item
            :label="$t('accountManage.bounsOdds') /*加奖赔率*/"
            prop="add_rate"
          >
            <el-input v-model="ruleForm.add_rate"></el-input>
          </el-form-item>
          <el-form-item
            :label="$t('accountManage.bounsOddsOn') /*加奖上限*/"
            prop="add_up"
          >
            <el-input v-model="ruleForm.add_up"></el-input>
          </el-form-item>
          <el-form-item
            :label="$t('accountManage.bounsOddsOff') /*加奖下限*/"
            prop="add_down"
          >
            <el-input v-model="ruleForm.add_down"></el-input>
          </el-form-item>
          <el-form-item
            :label="$t('accountManage.bounsOddsPercent') /*加奖抽成*/"
            prop="add_get_rate"
          >
            <el-input v-model="ruleForm.add_get_rate"></el-input>
          </el-form-item>
          <el-form-item
            :label="$t('accountManage.isUnk1') /*是否有灰球*/"
            prop="is_gray"
          >
            <el-radio-group v-model="ruleForm.is_gray">
              <el-radio :label="0">
                {{ $t('accountManage.none') /*无*/ }}
              </el-radio>
              <el-radio :label="1">
                {{ $t('accountManage.has') /*有*/ }}
              </el-radio>
            </el-radio-group>
          </el-form-item>
          <el-form-item
            :label="$t('accountManage.greyballOdds') /*灰球赔率*/"
            prop="gray_rate"
          >
            <el-input v-model="ruleForm.gray_rate"></el-input>
          </el-form-item>
          <el-form-item
            :label="$t('accountManage.specialCodeAmountLimit') /*特码金额限制*/"
            prop="name"
          >
            <el-button type="primary" plain>
              {{ $t('accountManage.add') /*增加*/ }}
            </el-button>
            <!-- <el-input v-model="ruleForm.odds"></el-input> -->
          </el-form-item>
          <el-table
            v-loading="listLoading"
            :data="ruleForm.limitcode_list"
            :element-loading-text="elementLoadingText"
            @selection-change="setSelectRows"
          >
            <!-- <el-table-column show-overflow-tooltip type="selection"></el-table-column> -->
            <el-table-column
              show-overflow-tooltip
              prop="code"
              :label="$t('accountManage.number') /*号码*/"
            ></el-table-column>
            <el-table-column
              show-overflow-tooltip
              prop="lmoney"
              :label="$t('accountManage.limitMoney') /*限制金额*/"
            ></el-table-column>
            <el-table-column
              show-overflow-tooltip
              :label="$t('common.operate') /*操作*/"
              width="60"
            >
              <template #default="{ row }">
                <el-button type="text" @click="handleDelete(row)">
                  {{ $t('accountManage.delete') /*删除*/ }}
                </el-button>
              </template>
            </el-table-column>
          </el-table>
          <el-form-item label="加奖金额限制" prop="name">
            <el-button type="primary" plain>
              {{ $t('accountManage.add') /*增加*/ }}
            </el-button>
            <!-- <el-input v-model="ruleForm.odds"></el-input> -->
          </el-form-item>
          <el-table
            v-loading="listLoading"
            :data="ruleForm.addcode_list"
            :element-loading-text="elementLoadingText"
            @selection-change="setSelectRows"
          >
            <!-- <el-table-column show-overflow-tooltip type="selection"></el-table-column> -->
            <el-table-column
              show-overflow-tooltip
              prop="code"
              :label="$t('accountManage.number') /*号码*/"
            ></el-table-column>
            <el-table-column
              show-overflow-tooltip
              prop="lmoney"
              :label="$t('accountManage.limitMoney') /*限制金额*/"
            ></el-table-column>
            <el-table-column
              show-overflow-tooltip
              :label="$t('common.operate') /*操作*/"
              width="60"
            >
              <template #default="{ row }">
                <el-button type="text" @click="handleDelete(row)">
                  {{ $t('accountManage.delete') /*删除*/ }}
                </el-button>
              </template>
            </el-table-column>
          </el-table>
        </el-form>
      </el-col>
    </el-row>
    <div slot="footer" class="dialog-footer">
      <el-button @click="close">取 消</el-button>
      <el-button type="primary" @click="save">确 定</el-button>
    </div>
  </el-dialog>
</template>

<script>
import { doEdit } from '@/api/roleManagement'
import { editScene } from '@/api/business.js'
import RulesEditDetail from '@/views/systemManagement/roleManagement/components/components/rulesEditDetail.vue'
export default {
  name: 'RoleManagementEdit',
  components: { RulesEditDetail },
  data() {
    return {
      form: {
        id: '',
      },
      ruleForm: {
        name: '',
        region: '',
        delivery: false,
        type: [],
        resource: '',
        desc: '',
      },
      rules: {
        permission: [
          { required: true, trigger: 'blur', message: '请输入权限码' },
        ],
      },
      title: '',
      dialogFormVisible: false,
    }
  },
  created() {},
  methods: {
    showEdit(row) {
      if (!row) {
        this.title = '新增玩法'
      } else {
        this.title = '编辑玩法'
        this.ruleForm = Object.assign({}, row)
      }
      this.dialogFormVisible = true
    },
    close() {
      // this.$refs['form'].resetFields()
      // this.form = this.$options.data().form
      this.dialogFormVisible = false
      this.close()
    },
    save() {
      this.$refs['form'].validate(async (valid) => {
        if (valid) {
          let data = await editScene(this.ruleForm)
          if (data.code == 0) {
            this.$baseMessage(data.msg, 'success')
            this.$emit('fetch-data')
            this.close()
          } else {
            this.$baseMessage(data.msg, 'warm')
          }
        } else {
          return false
        }
      })
    },
  },
}
</script>
